package com.bwie.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.bwie.service.UserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginInfoVo;
import com.bwie.vo.ToKenVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * TODO
 *
 * @Description
 * @Author 36167
 * @Date 2025/3/8 10:07
 **/


@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/login")
    public R login( LoginInfoVo loginInfoVo){
        return userService.login(loginInfoVo);
    }

    @PostMapping("/reftoken")
    public R reftoken(@RequestBody ToKenVo token){
        System.out.println(token);
        return userService.refTokne(token.getToken());
    }

    @GetMapping("/list")
    public R list(){
        return userService.list1();
    }

    @GetMapping("/time")
    public R time(String time){
        Date date = new Date(time);
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            DateTime dateTime = DateUtil.offsetDay(date, i);
            DateTime dateTime1 = DateUtil.offsetDay(date, -i);
            String format = DateUtil.format(dateTime, "yyyy-MM-dd");
            String format1 = DateUtil.format(dateTime1, "yyyy-MM-dd");
             list.add(format);
             list.add(format1);
        }
        Set<String> collect = list.stream().collect(Collectors.toSet());
        Stream<String> sorted = collect.stream().sorted();
       return R.OK(sorted);
    }


}
